﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZSZ.DTO;
using ZSZ.IDAL;
using ZSZ.IService;
using ZSZ.Model;
using ZSZ.Service;
using static ZSZ.Common.CommonHelper;

namespace TestService.Controllers
{
    public class HomeController : Controller
    {
        public IRoleService RoleService { get; set; }
        public ISettingService SettingService { get; set; }
        public IAdminUserService AdminUserService { get; set; }
        //public IDbSession DbSession { get; set; }
        public ActionResult Index()
        {
            //SettingService.Add(new Setting { Name="系统邮件账号",Value= "tianxun0754@163.com" });
            //SettingService.Add(new Setting { Name = "系统邮件密码", Value = "159753lyq" });
            ViewData.Model = RoleService.GetAll().ToList();
            return View();
        }
        
        [HttpPost]
        public ActionResult Add(Role model)
        {
           // throw new Exception("错误日志");
            //DbSession.RoleDal.Add(model);
            //RoleService.Add(model);
            return RedirectToAction("Index");
        }

        /// <summary>
        /// 验证码测试
        /// </summary>
        /// <returns></returns>
        public ActionResult GetValidateCode()
        {
            //首先实例化验证码的类  
            ValidateCode validateCode = new ValidateCode();
            validateCode.Width = 200;
            //validateCode.Height = 50;
            //生成验证码指定的长度  
            string code = validateCode.GetRandomString(6);
            //创建验证码的图片  
            byte[] bytes = validateCode.CreateImage(code);
            //最后将验证码返回  
            return File(bytes, @"image/jpeg");
        }

        public ActionResult List(AdminUserSearchOptions options, int pageIndex = 1)
        {
            long total;
            int pageSize = 10, maxPagerCount = 10;
            AdminUserDTO[] list = AdminUserService.GetPagedData(options, out total, pageIndex, pageSize);
            ViewBag.totalCount = total;
            ViewBag.pageIndex = pageIndex;
            ViewBag.pageSize = pageSize;
            ViewBag.maxPagerCount = maxPagerCount;
            return View(list);
        }
    }
}